<template>
  <!-- 背景制作 -->
  <div class="bgc"></div>
  <div class="container">
    <!-- 轮播图部分 -->
    <swiper :modules="modules" :pagination="{ clickable: true }" :autoplay="{ delay: 2000 }">
      <swiper-slide v-for="(item) in swiperList" :key="item.id">
        <img :src="item.imageUrl" alt="" class="image">
      </swiper-slide>
    </swiper>

    <!-- 导航区 -->
    <div class="nav-list">
      <div class="nav-item" @click="toMoreDetail(index + 1)"
      v-for="item, index in navList" :key="item.id">
        <img :src="item.imageUrl" alt="" :class="index > 4 ? 'small' : ''">
        <span>{{ item.name }}</span>
      </div>
    </div>

    <!-- 广告区域 -->
    <div class="adv">
      <div class="left">
        <img :src="advList[0]?.imageUrl" alt="">
      </div>
      <div class="right">
        <div class="top">
          <img :src="advList[1]?.imageUrl" alt="">
        </div>
        <div class="bottom">
          <img :src="advList[2]?.imageUrl" alt="">
        </div>
      </div>
    </div>
    <!-- 猜你喜欢 -->
    <Recommend :list="likeArr" title='猜你喜欢' />
    <button class="more" @click="toMore">查看更多</button>

    <!-- 热门推荐 -->
    <Recommend :list="recommendArr" title='热门推荐' />
    <button class="more" @click="toMore">查看更多</button>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import type { data, navItemList, advertisementList, recommendResponseData, recommendItemList } from '@/types'
import { reqSwiperData, reqNavListData, reqAdvListData, reqHotRecommend, reqLike } from '@/api'
import { Pagination, Autoplay } from 'swiper'
import { Swiper, SwiperSlide } from 'vue-awesome-swiper'
import Recommend from './recommend.vue'
import { useRouter } from 'vue-router'
const router = useRouter()
// import swiper module styles
import 'swiper/css'
import 'swiper/css/pagination'
const modules = [Pagination, Autoplay]
//轮播图数据列表
let swiperList = ref<data>([])
//导航列表数据
let navList = ref<navItemList>([])
//广告栏数据图片
let advList = ref<advertisementList>([])
//猜你喜欢数据
let recommendArr = ref<recommendItemList>([])
let likeArr = ref<recommendItemList>([])
// 轮播图数据
const getSwiperList = async () => {
  let res = await reqSwiperData()
  swiperList.value = res.data
}
//导航列表
const getNavList = async () => {
  const res = await reqNavListData()
  navList.value = res.data
}
const  toMoreDetail =(index:number)=>{
  console.log(index)
}
//获取广告数据
const getAdvList = async () => {
  const res = await reqAdvListData()
  advList.value = res.data
}
//热门推荐
const getRecommendList = async () => {
  const res = await reqHotRecommend()
  recommendArr.value = res.data
}
//猜你喜欢
const getLikeList = async () => {
  const res = await reqLike()
  likeArr.value = res.data
}
//查看更多
const toMore = () => {
  router.push('/more')
}

onMounted(() => {
  getSwiperList()
  getNavList()
  getAdvList()
  getRecommendList()
  getLikeList()
})


</script>


<style scoped lang="less">
.bgc {
  width: 375px;
  height: 100px;
  background-color: #f3514f;
  border-radius: 0 0 10px 10px;
  position: absolute;
}

.container {
  padding: 0 8px;
  width: 100%;
  height: 100%;
  position: relative;
  background-color: transparent;
  box-sizing: border-box;
  padding-bottom: 50px;

  .more {
    width: 100%;
    border-radius: 20px;
    background-color: #fff;
    height: 40px;
    font-size: 16px;
    color: rgba(35, 38, 40, 0.7);
    border: none;
  }

  .swiper {
    --swiper-theme-color: #ff6600;

    .image {
      width: 100%;
      border-radius: 8px;
    }
  }

  // 导航列表样式
  .nav-list {
    display: flex;
    flex-wrap: wrap;
    margin: 10px 0;
    border-radius: 9px;
    padding: 10px 0;
    background-color: white;

    .nav-item {
      width: 20%;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;

      img {
        width: 33px;
        height: 33px;
      }

      .small {
        width: 25px;
        height: 25px;
      }

      span {
        font-size: 12px;
        margin-top: 4px;
        margin-bottom: 5px;
      }
    }
  }

  // 广告列表样式
  .adv {
    width: 100%;
    padding: 5px 4px;
    background-color: white;
    box-sizing: border-box;
    border-radius: 9px;
    display: flex;

    .left,
    .right {
      width: 50%;
      height: 100%;
      padding: 4px 4px 0 4px;
      display: flex;

      img {
        width: 100%;
      }
    }

    .right {
      height: 100%;
      flex-direction: column;
      justify-content: space-between;

      .bottom {
        margin-top: 2px;
      }
    }
  }





}
</style>
